有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将触摸事件从回收器传递到其父LinearLayout

我有这样的想法:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
tools:context="cntxt">


<LinearLayout
    安卓:id="@+id/main_layout"
    安卓:layout_width="match_parent"
    安卓:layout_height="wrap_content"
    安卓:orientation="vertical">

    <!-- Title -->
    <TextView
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:background="@color/colorPrimary"
        安卓:gravity="center"
        安卓:padding="20dp"
        安卓:text="@string/title"
        安卓:textColor="@安卓:color/white"
        安卓:textSize="17sp" />

        <!-- Recycler -->
        <CustomRecyclerView
            安卓:id="@+id/main_activity_rv"
            安卓:layout_width="match_parent"
            安卓:layout_height="wrap_content"
            安卓:background="@安卓:color/white"
            安卓:scrollingCache="false" />
</LinearLayout>

当布局滚动到顶部时,当用户用手指进行类似于“滑动刷新”的移动时,我需要在Y轴上制作一个平移动画。换句话说,如果回收者在上面,我需要跟随整个回收者的手指移动

我试图将onTouch侦听器附加到回收器上,但回收器的内部卷轴使情况变得不清楚。 有什么想法来实现这个动画

如果我将onTouchListener附加到主_布局,并从Inner textview进行播放,动画将正常播放。但当我触摸回收器时,什么也没发生(除了回收器的内部卷轴) 先谢谢你


共 (1) 个答案

  1. # 1 楼答案

    使最外层成为一层

    SwipeRefreshLayout 
    

    而不是相对的布局。这将以任何方式为您提供刷新功能

    另外请注意,在上面提到的滑动布局下,只能有一个直接的子视图,所以无论你放什么。。。一定要把它放在线性布局中

    您可以附加一个OnRefreshListener来监听刷新布局的拉动